home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------
- BRIEFKEY.C -- Extension DLL for E! - version 1.0
-
- To compile: nmake /f briefkey.mak
-
- Once compiled, copy BRIEFKEY.EWD to your USER directory.
-
- To use this DLL simply load it from the user menu or add its name to the
- list of autoloaded Extension DLLs by using the Autoload dialog box from
- the User Menu of E!. That's all.
-
- BRIEFKEY emulates the behavior of the Home/End keys in the Brief editor.
- If you press the END key once, the cursor moves to the end of the current line.
- Pressing it a second time moves it to the end of the current page, and pressing
- it a third time moves it to the end of the file. Home works similarly in the
- reverse direction. If you use another function key, this process is reset.
-
- ------------------------------------------------*/
-
- #include <windows.h>
- #include "ewapi2.h"
-
-
- static int nHome = 0;
- static int nEnd = 0;
-
- int FAR PASCAL _export FuncEntryHook(unsigned int command)
- {
- static BOOL bInUse = FALSE;
-
- if (!bInUse)
- // We need a reentrancy flag because the calls to EWTopOfPage and to
- // EWTopOfText would cause the keystroke counter to be reset: FuncEntryHook
- // will be called for ALL editing functions.
- {
- bInUse = TRUE;
- if (command == ew_BeginLine)
- {
- nEnd = 0;
- switch (nHome)
- {
- case 0: // First keystroke
- EWBeginLine( 0 ); // Don't use the default, because we want to
- nHome++; // stay on the current line if already at BOL
- bInUse = FALSE;
-
- return (1); // We don't allow the standard function to be executed
-
- case 1: // Second keystroke
- EWTopOfPage(1);
- nHome++;
- bInUse = FALSE;
- return (1); // We don't allow the standard function to be executed
-
- case 2: // Third keystroke
- EWTopOfText(1);
- nHome = 0;
- bInUse = FALSE;
- return (1); // We don't allow the standard function to be executed
- }
- }
- else
- nHome = 0; // Otherwise reset counter
-
- if (command == ew_EndLine)
- // We must check for both commands anyway to be sure to correctlt reset
- // the counters. For example if we hit Home twice and then hit the End key.
- {
- nHome = 0;
- switch (nEnd)
- {
- case 0:
- nEnd++;
- EWEndLine( 0, 0 ); // Don't use the default because we want to stay
- bInUse = FALSE; // where we are if we are already at EOL
-
- return (1); // We don't allow the standard function to be executed
-
- case 1:
- EWTopOfPage(0);
- EWEndLine( 0, 0 ); // make sure that we are still at EOL
- nEnd++;
- bInUse = FALSE;
- return (1);
-
- case 2:
- EWTopOfText(0);
- nEnd = 0;
- bInUse = FALSE;
- return (1);
- }
- }
- else
- nEnd = 0;
-
- bInUse = FALSE;
- }
- return (0); // Standard behavior
- }
-
- int FAR PASCAL _export NotifyHook(unsigned int code, unsigned int wParam, long lParam)
- {
- if (code == EWNotify_ActWinChanged)
- {
- nHome = 0;
- nEnd = 0;
- }
- }
-
- int FAR PASCAL _export _WEP(int nParameter)
- {
- // Remove hook before unloading
- EWRemoveHook(EWHook_FunctionEntry, FuncEntryHook);
- EWRemoveHook(EWHook_Notify, NotifyHook);
- return (1);
- }
-
- int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
- {
-
- if (wHeapSize > 0)
- UnlockData (0) ;
- // Install hook on function entry
- EWSetHook(EWHook_FunctionEntry, FuncEntryHook);
- EWSetHook(EWHook_Notify, NotifyHook);
- return (1) ;
- }
-
-